public class Main {
    //求各位数平方和
    public static int func(int n){
        int sum = 0;
        while(n != 0){
            int t = n % 10;
            sum = sum + t;
            n = n /10;
        }
        return sum;
    }
    //用快慢指针求相遇值
    public static boolean ishappy(int n){
        int slow = n;
        int fast = func(n);
        while (slow != fast){
            slow = func(slow);
            fast = func(func(fast));
        }
        return slow == 1;
    }
    public static void main(String[] args) {
        System.out.println(ishappy(2));
    }
}